package com.aode.common.bean.response;

import android.os.Parcel;
import android.os.Parcelable;
import android.widget.ImageView;

import androidx.databinding.BaseObservable;
import androidx.databinding.Bindable;
import androidx.databinding.BindingAdapter;

import com.aode.common.url.UrlGather;
import com.bumptech.glide.Glide;

import java.math.BigDecimal;
import java.util.Date;

public class Music extends BaseObservable implements Parcelable {
    private static final long serialVersionUID = 1L;

    public Music(){}
    /**
     * 音乐ID
     */
    private Integer musicId;
    /**
     * 音乐名字
     */
    private String musicName;
    /**
     * 音乐价格
     */
    private BigDecimal musicPrice;
    /**
     * 歌手
     */
    private String musicMusician;
    /**
     * 创建时间
     */
    private Date musicDate;
    /**
     * 音乐封面
     */
    private String musicCover;
    @BindingAdapter({"imagepath"})
    public static void loadImage(ImageView imageView, String imageUrl){
        Glide.with(imageView.getContext()).load(UrlGather.BASE_URL+imageUrl).into(imageView);
    }
    /**
     * 音乐作品
     */
    private String musicProduct;
    /**
     * 音乐所属用户
     */
    private Integer musicUserId;
    /**
     * 是否有版权
     */
    private Integer musicCopyright;
    /**
     * 音乐简介
     */
    private String musicIntroduction;
    /**
     * 音乐歌词
     */
    private String musicLyric;

    /**
     * 音乐风格
     */
    private String musicStyle;

    private String userName;


    protected Music(Parcel in) {
        if (in.readByte() == 0) {
            musicId = null;
        } else {
            musicId = in.readInt();
        }
        musicName = in.readString();
        musicMusician = in.readString();
        musicCover = in.readString();
        musicProduct = in.readString();
        if (in.readByte() == 0) {
            musicUserId = null;
        } else {
            musicUserId = in.readInt();
        }
        if (in.readByte() == 0) {
            musicCopyright = null;
        } else {
            musicCopyright = in.readInt();
        }
        musicIntroduction = in.readString();
        musicLyric = in.readString();
        musicStyle = in.readString();
        userName = in.readString();
    }

    public static final Creator<Music> CREATOR = new Creator<Music>() {
        @Override
        public Music createFromParcel(Parcel in) {
            return new Music(in);
        }

        @Override
        public Music[] newArray(int size) {
            return new Music[size];
        }
    };

    public Integer getMusicId() {
        return musicId;
    }

    public void setMusicId(Integer musicId) {
        this.musicId = musicId;
    }
    @Bindable
    public String getMusicName() {
        return musicName;
    }

    public void setMusicName(String musicName) {
        this.musicName = musicName;
    }

    public BigDecimal getMusicPrice() {
        return musicPrice;
    }

    public void setMusicPrice(BigDecimal musicPrice) {
        this.musicPrice = musicPrice;
    }
    @Bindable
    public String getMusicMusician() {
        return musicMusician;
    }

    public void setMusicMusician(String musicMusician) {
        this.musicMusician = musicMusician;
    }

    public Date getMusicDate() {
        return musicDate;
    }

    public void setMusicDate(Date musicDate) {
        this.musicDate = musicDate;
    }
    @Bindable
    public String getMusicCover() {
        return musicCover;
    }

    public void setMusicCover(String musicCover) {
        this.musicCover = musicCover;
    }

    public String getMusicProduct() {
        return musicProduct;
    }

    public void setMusicProduct(String musicProduct) {
        this.musicProduct = musicProduct;
    }

    public Integer getMusicUserId() {
        return musicUserId;
    }

    public void setMusicUserId(Integer musicUserId) {
        this.musicUserId = musicUserId;
    }

    public Integer getMusicCopyright() {
        return musicCopyright;
    }

    public void setMusicCopyright(Integer musicCopyright) {
        this.musicCopyright = musicCopyright;
    }

    @Bindable
    public String getMusicIntroduction() {
        return musicIntroduction;
    }

    public void setMusicIntroduction(String musicIntroduction) {
        this.musicIntroduction = musicIntroduction;
    }

    public String getMusicLyric() {
        return musicLyric;
    }

    public void setMusicLyric(String musicLyric) {
        this.musicLyric = musicLyric;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getMusicStyle() {
        return musicStyle;
    }

    public void setMusicStyle(String musicStyle) {
        this.musicStyle = musicStyle;
    }

    @Override
    public String toString() {
        return "Music{" +
                ", musicId=" + musicId +
                ", musicName=" + musicName +
                ", musicPrice=" + musicPrice +
                ", musicMusician=" + musicMusician +
                ", musicDate=" + musicDate +
                ", musicCover=" + musicCover +
                ", musicProduct=" + musicProduct +
                ", musicUserId=" + musicUserId +
                ", musicCopyright=" + musicCopyright +
                ", musicIntroduction=" + musicIntroduction +
                ", musicLyric=" + musicLyric +
                "}";
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        if (musicId == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeInt(musicId);
        }
        dest.writeString(musicName);
        dest.writeString(musicMusician);
        dest.writeString(musicCover);
        dest.writeString(musicProduct);
        if (musicUserId == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeInt(musicUserId);
        }
        if (musicCopyright == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeInt(musicCopyright);
        }
        dest.writeString(musicIntroduction);
        dest.writeString(musicLyric);
        dest.writeString(musicStyle);
        dest.writeString(userName);
    }
}
